const Sequelize = require('sequelize')


const sequelize = new Sequelize(
	process.env.DB_DATABASE,
	process.env.DB_USER,
	process.env.DB_PWD,
	{
		host: process.env.DB_HOST,
		port: process.env.DB_PORT,
    dialect: 'mysql',
    // 是否显示SQL
		logging: true,
		// 维护数据库时间为北京时间
		timezone: '+08:00',
		define: {
      // false  `createdAt`、 `updatedAt` will not be created
      timestamps: true,
      // 生成deletedAt 字段 用于软删除
      paranoid: true,
      createdAt: "created_at", 
      updatedAt: "updated_at",
      deletedAt: "deleted_at",
      // 字段下划线连接单词
			underscored: true,
			// 禁止模型名称转换为复数
			freezeTableName: true
    }
	}
)

sequelize.sync({
  // ture 删除表重新创建
  force: false
})

module.exports = sequelize
